package com.teach.socket;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created by Administrator on 2020/7/19.
 */
public class Client {

    public static void client() throws Exception{
        //指定端口
        Socket socket = new Socket("127.0.0.1",8080);
        //向服务的发送请求
        PrintWriter writer = new PrintWriter(socket.getOutputStream());
        writer.write("我是客户端");
        writer.flush();
        socket.shutdownOutput();

        InputStreamReader in = new InputStreamReader(socket.getInputStream());
        BufferedReader bf = new BufferedReader(in);
        String result = null;
        while ((result = bf.readLine()) != null){
            System.out.print("client======" + result);
        }
        socket.shutdownInput();
        writer.close();
        in.close();
        bf.close();
        socket.close();
    }



    public static void main(String[] args) throws Exception{
        client();
    }
}
